<?php


namespace App\Tool;


class GetOrderPrice
{
    protected $user_id;

    function __construct()
    {
        $this->user_id = resolve('weapp_user')['id']??false;

    }



    function getTotalMoney(array $goods_list,$price_key,$num_key){


        $total_money = 0;
        foreach ($goods_list as $k => $v) {


//            $price=$v['price'];
//
//            //判断秒杀商品
//            if($v['snapped_price']) $price=$v['snapped_price'];

            $price=$this->getRealPrice($v);

            //计算订单总价格
            $total_money += ($price * $v[$num_key]);


        }

        return $total_money;


    }


    function getRealPrice($goods_sku_item){


        $price=$goods_sku_item['price'];

        //判断秒杀商品
        if($goods_sku_item['snapped_price']) $price=$goods_sku_item['snapped_price'];

        return $price;

    }

}
